package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallCommissionApplyMapper;
import org.linlinjava.litemall.db.domain.LitemallCommissionApply;
import org.linlinjava.litemall.db.domain.LitemallCommissionApplyExample;
import org.linlinjava.litemall.db.domain.LitemallCouponExample;
import org.linlinjava.litemall.db.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 佣金提现管理
 */
@Component
public class LitemallCommissionApplyService {
    @Autowired
    private LitemallCommissionApplyMapper commissionApplyMapper;


    public LitemallCommissionApply queryOneByExample(LitemallCommissionApplyExample example) {
        return commissionApplyMapper.queryOneByExample(example);
    }

    public List<LitemallCommissionApply> queryByExample(PageVO<LitemallCommissionApply, LitemallCommissionApply> page) {
        if (page.getSize() == null) {
            page.setSize(10);
        }
        if (page.getPage() == null) {
            page.setPage(0);
        }
        if (page.getCondition() != null) {
        }
        LitemallCommissionApplyExample example = new LitemallCommissionApplyExample();
        LitemallCommissionApplyExample.Criteria criteria = example.createCriteria();
        if (page.getBeginTime() != null) {
            criteria.andCreatedTimeGreaterThanOrEqualTo(page.getBeginTime());
        }
        if (page.getEndTime() != null) {
            criteria.andCreatedTimeLessThanOrEqualTo(page.getEndTime());
        }
        if (page.getCondition() != null) {
            LitemallCommissionApply condition = page.getCondition();
            if (condition.getUserId() != null) {
                criteria.andUserIdEqualTo(condition.getUserId());
            }
            if (condition.getStatus() != null) {
                criteria.andStatusEqualTo(condition.getStatus());
            }
            if (condition.getUsername() != null) {
                criteria.andUsernameEqualTo(condition.getUsername());
            }
        }
        example.orderBy(" created_time desc");
        PageHelper.startPage(page.getPage(), page.getSize());
        return commissionApplyMapper.queryByExample(example);
    }

    public int update(LitemallCommissionApply param) {
        return commissionApplyMapper.update(param);
    }

    public int save(LitemallCommissionApply param) {
        return commissionApplyMapper.save(param);
    }

    public int delete(LitemallCommissionApply param) {
        return commissionApplyMapper.delete(param);
    }
}
